package com.telit.uav.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.telit.common.entity.DataReturn;
import com.telit.common.entity.PageData;
import com.telit.uav.dto.UavMediaSourceDTO;
import com.telit.uav.service.UavMediaSourceService;
import com.telit.uav.service.UavQueryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author zhouyu
 * @description 无人机上传文件接口
 */
@RestController
@RequestMapping("/uav-media-source")
@Api(tags = "无人机巡航-多媒体资源", description = "/uav-media-source")
public class UavMediaSourceController {

    @Autowired
    private UavMediaSourceService uploadMediaService;

    @Autowired
    private UavQueryService uavQueryService;

    //TODO：v1.1.0
//    @PostMapping(value = "/uploadFile",produces = "application/json;charset=UTF-8")
//    @ApiOperation("无人机上传文件接口")
//    public DataReturn uploadFile(@RequestParam(value = "files") List<MultipartFile> files,
//                                 @Validated FileUploadLog fileUploadLog) {
//        if (CollectionUtils.isEmpty(files)){
//            return DataReturn.failure(ResultCode.REQUEST_PARAMS_CHECK_ERROR,"上传文件不能为空");
//        }
//        files.forEach(file ->{
//            fileUploadLog.setUploadTime(new Date());
//            String path = MinioUtils.upload(file, MinioConstants.BUCKET_FORESTRY_NAME, MinioConstants.BUCKET_UAV_SUFFIX_NAME);
//            // 获取源文件名称
//            String originalFilename=file.getOriginalFilename();
//            fileUploadLog.setFileName(originalFilename);
//            fileUploadLog.setFilePath(path);
//            String type = MinioUtils.checkFileType(originalFilename.substring(originalFilename.lastIndexOf(".")+1));
//            fileUploadLog.setFileType(type);
//            fileUploadLog.setUavName(uavQueryService.queryNameByCode(fileUploadLog.getUavCode()));
//            uploadMediaService.uploadFile(fileUploadLog);
//        });
//        return DataReturn.ok();
//    }

    @GetMapping("/listByPage")
    @ApiOperation("分页条件查询无人机多媒体资源")
    public DataReturn listByPage(@RequestParam Integer current,
                                 @RequestParam Integer size,
                                 @ModelAttribute UavMediaSourceDTO uavMediaSourceDTO) {
        IPage<UavMediaSourceDTO> uavMediaSourceDTOIPage = uploadMediaService.listByPage(current, size,
                uavMediaSourceDTO);
        return DataReturn.ok(new PageData<>((int) uavMediaSourceDTOIPage.getTotal(), current, size,
                uavMediaSourceDTOIPage.getRecords()));
    }

}
